<script>
    $(document).ready(function(){                
        $('#add_units').validate({
            rules : {
                unitcode : { required : true}
			},
            messages : {
                unitcode : { required : ' Please enter unit code'}
            }
        }); 				
	});
</script>
<?php include './pages/stockMenu.php'; ?>
<div class = "mainContent">
	<div class = "masterData">
		<h3>Available Units</h3>
		<?php
			include("./system/dbconnection.php");
			if($result =mysql_query("SELECT * FROM units ")){
				if(mysql_num_rows($result)){
					echo "<table border='1' style='width:100%' cellspacing='0' class='masterTable'>";
					echo "<tr><th>Unit Id</th><th>Unit Name</th><th>Unit Description</th></tr>";
					while($row = mysql_fetch_array($result)){
					  echo "<tr>";
					  echo "<td>" . $row['unitId'] . "</td>";
					  echo "<td>" . $row['unitCode'] . "</td>";
					  echo "<td>" . $row['unitDescription'] . "</td>";
					  echo "</tr>";
					  }
					echo "</table>";		
				}else{
					echo "No Data in Database";
				}
			}
		?>	
	</div>
	<div class="mainForm">
		<form name="add_units" id="add_units"  action="./system/action/addUnits.php" method="POST" style="width:100%">
			<table>
				<tr>
					<td colspan="2">
						<?php
						if(isset($_SESSION['error']) && $_SESSION['error'] != ""){ ?>
							<div class="error">
								<?php echo $_SESSION['error']; ?>
							</div>
						<?php } else if(isset($_SESSION['success']) && $_SESSION['success'] != ""){?>
							<div class="success">
								<?php echo $_SESSION['success']; ?>
							</div>
						<?php }
						?>
					</td>
				</tr>
				<tr>
					<td>Unit: <label class="mandatory">*</label></td>
					<td> <input type="text" name="unitcode" id="unitcode" class="required" ></td></tr>
				<tr>
					<td>Description: </td>
					<td><input type="text" name="unitDescription" id="unitDescription"></td>
				</tr>
				<tr>
					<td></td>
					<td><input type="submit" name="submit" value="submit"/></td>
				</tr>
			</table>	
		</form>
	</div>
</div>